import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class RegisterInterface{
	private JFrame frame;
	private JButton signIn;
	private JLabel welcomeLabel, idJL, pwJL, pwJL2;
	private JTextField idJT;
	private JPasswordField pass1, pass2;
	private JPanel jp1, jp2, jp3, jp4;

	public RegisterInterface(){
		signIn = new JButton("ע��");
		signIn.addActionListener(new Lis());
		signIn.setSize(new Dimension(100, 30));
		welcomeLabel = new JLabel("��ӭע�����Ѳ�ϵͳ");
		idJL = new JLabel("�������ֻ��ţ�");
		pwJL = new JLabel("���������룺");
		pwJL2 = new JLabel("��ȷ�����룺");
		idJT = new JTextField(12);
		pass1 = new JPasswordField(12);
		pass2 = new JPasswordField(12);
		jp1 = new JPanel();
		jp2 = new JPanel();
		jp3 = new JPanel();
		jp4 = new JPanel();
		frame = new JFrame("���Ѳ�");
	}
	
	public void launch(){
		frame.setSize(400, 250);
		frame.setResizable(false);
		frame.invalidate(); // ��֤�������Ч�Ĳ���);;
		frame.setLayout(new GridLayout(5, 1));
		jp1.add(welcomeLabel);
		frame.add(jp1);
		//jp.setLayout(new GridLayout(3, 2));
		jp2.add(idJL);
		jp2.add(idJT);
		frame.add(jp2);
		jp3.add(pwJL);
		jp3.add(pass1);
		frame.add(jp3);
		jp4.add(pwJL2);
		jp4.add(pass2);
		frame.add(jp4);
		frame.add(signIn);
		
		//frame.add(jp,"Center");
		
		frame.setVisible(true);
		frame.setLocationRelativeTo(null);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	//����һ���ڲ���Lis
	class Lis implements ActionListener{
		public void actionPerformed(ActionEvent e) {
			Object source = e.getSource();
			String pw1 = pass1.getText();
			String pw2 = pass2.getText();
			String id = idJT.getText();
			if(source == signIn) {
				if(pw1.equals(pw2)) {
					LoginInterface.onlineID = id;
					try {
						//System.out.printf("%s\t%s", id, pw1);
						DatabaseCtrl.init();
						DatabaseCtrl.insertUserData(id, pw1);
						DatabaseCtrl.close();
					} catch (Exception e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
					//��ʾע��ɹ������½�������������
					JOptionPane.showMessageDialog(null, "ע��ɹ�", "��ʾ!", JOptionPane.INFORMATION_MESSAGE);
					frame.dispose();
					LoginInterface myShow = new LoginInterface();
					myShow.launch();
					
				}else {
					//��ʾ���벻һ��
					JOptionPane.showMessageDialog(null, "����������벻��ȷ", "������ʾ!", JOptionPane.ERROR_MESSAGE);
					
					
				}
			}
			
		}
	}
	
	public static void main(String[] args) {
		RegisterInterface myShow = new RegisterInterface();
		myShow.launch();
	}

}